package com.kandinfo.isbnmanage.repository;

import java.util.List;

import org.springframework.data.jpa.repository.Query;

import com.kandinfo.base.common.repository.BaseRepository;
import com.kandinfo.isbnmanage.domian.IsbnDistribute;

public interface IsbnDistributeRepository extends BaseRepository<IsbnDistribute, Long> {

	@Query(value=" SELECT ii.* FROM isbn_distribute ii where ii.barcode = ?1 and ii.type = ?2 " ,nativeQuery=true)
	IsbnDistribute findByBarcodeAndType(String barcode,int type );
	
	@Query(value=" SELECT ii.* FROM isbn_distribute ii where ii.ref_key = ?1 and ii.type = ?2 " ,nativeQuery=true)
	IsbnDistribute findByRefKeyAndType(Long refKey, int type);

	@Query(value=" select count(ii.id) from isbn_distribute id,isbn_information ii "
			+ "where ii.status = 0 and id.barcode = ii.barcode and id.type = 0 and ii.barcode = ?1",nativeQuery = true)
	Integer getInformationFillCandoUndoCount(String barcode);

	@Query(value=" SELECT ii.* FROM isbn_distribute ii where ii.ref_key = ?1 and ii.type != 0" ,nativeQuery=true)
	List<IsbnDistribute> findByInfoId(Long isbnInformationId);

	

}
